"""
@name : 11.python自省
@author : wenyao
@projectname: sanchuanglianxi
"""
class A:
    name = "wen"
    __max = "max"

    def __init__(self):
        self.age = 18

    def talk(self):
        print("i am talk")

a = A()
#print(a.xx)
#检查是否含有成员属性
print(hasattr(a, "xx"))
print(hasattr(a, "name"))
#print(hasattr(a,"_A__max"))

#访问成员属性
# if hasattr(a,"xx"):
#     print(getattr(a,"xx"))
#
# if hasattr(a,"talk"):
#     b = getattr(a,"talk")
#     b()
#
#
# #设置成员属性
# if not hasattr(a,"tmp"):
#     setattr(a, "tmp", "hello world")
#     print(getattr(a,"tmp"))
#
# #添加方法
# def func1():
#     print("this is func1")
#
# if not hasattr(a,"func1"):
#     setattr(a,"func2",func1)
#     print(id(func1),id(a.func2))
#     print(id(getattr(a,"func2")))
#     a.func2()
#
# #删除
# if hasattr(a, "func2"):
#     delattr(a,"func2")


#判断模块中的方法属性
# >>> hasattr(mod1, "func2")
# False
# >>> hasattr(mod1, "a")
# True
# >>> setattr(mod1,"b","test b")
# >>> mod1.b
# 'test b'

# async def()